import 'dart:math';

import 'package:audioplayers/audioplayers_api.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:mahjong/const/MahjongConst.dart';

class AudioPlayUtil {
  static Future<void> playAudioAction(String action) async {
    try {
      /*  audioCache.fixedPlayer = audioPlayer;
      audioPlayer.pause(); */
      await audioCache.play('sounds/action/' + action + ".mp3");
    } catch (e, stack) {
      ErrorWidget.builder(
          _debugReportException(ErrorDescription("building "), e, stack));
    }
  }

  static FlutterErrorDetails _debugReportException(
    DiagnosticsNode context,
    dynamic exception,
    StackTrace stack, {
    InformationCollector informationCollector,
  }) {
    final FlutterErrorDetails details = FlutterErrorDetails(
      exception: exception,
      stack: stack,
      library: 'widgets library',
      context: context,
      informationCollector: informationCollector,
    );
    FlutterError.reportError(details);
    return details;
  }

  static Future<void> playExportCard(int cardId) async {
    try {
      await audioCache.play('sounds/card/' + cardId.toString() + "s.mp3");
    } on Exception {} catch (e) {
      print(e);
    }
  }

  static Future<void> playSoundMessage(String message) async {
    try {
      await audioCache.play('sounds/message/' + message + ".mp3");
    } on Exception {} catch (e) {
      print(e);
    }
  }
}
